package com.litchi.activity;

import com.litchi.R;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class WebActivity extends Activity implements OnClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_web);
		findViewById(R.id.img_back).setOnClickListener(this);
		initWebView();
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void initWebView() {
		// ��ַ
		String url = getIntent().getStringExtra("url");
		TextView tvTitle = (TextView) findViewById(R.id.tv_title);
		WebView mWebView = (WebView) findViewById(R.id.webView1);
		final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar1);
		WebSettings settings = mWebView.getSettings();
		settings.setGeolocationEnabled(true);
		settings.setJavaScriptEnabled(true);
		settings.setAllowFileAccess(true);
		settings.setDomStorageEnabled(true);
		settings.setLoadsImagesAutomatically(true);
		settings.setBuiltInZoomControls(true);

		tvTitle.setText("丝绸商城");

		mWebView.loadUrl(url);
		mWebView.setWebChromeClient(new WebChromeClient() {

			@Override
			public void onGeolocationPermissionsHidePrompt() {
				// TODO Auto-generated method stub
				super.onGeolocationPermissionsHidePrompt();
			}

			@SuppressWarnings("unused")
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return false;

			}

			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				super.onProgressChanged(view, newProgress);
				progressBar.setProgress(newProgress);
				if (progressBar.getProgress() == 100) {
					progressBar.setVisibility(View.GONE);
				}
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_back:
			finish();
			break;

		default:
			break;
		}
	}

}
